package com.example.myapplication.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.myapplication.fragment.DeviceFragment;
import com.example.myapplication.util.OrderedProperties;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {

    private List<DeviceFragment> fragments;
    //产品列表
    private OrderedProperties props;


    public MyFragmentPagerAdapter(@NonNull FragmentManager fm, int behavior, OrderedProperties props) {
        super(fm, behavior);
        fragments = new ArrayList<>();
        this.props = props;
        Set<String> strings = this.props.stringPropertyNames();
        for (String string : strings) {
            fragments.add(new DeviceFragment(string, this.props.getProperty(string)));
        }
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }
}
